import axios from 'axios'
import { onMounted, ref } from 'vue';

// CC-- 导入pinia的两个方法
import { storeToRefs } from "pinia";
import {CStore} from '../../stores/counter'

// CC-- 解构出pinia中存储的数据
const $store = CStore()

export const getCityData = ()=> {

    // 存储热门城市
    let hotCities = ref([{name:'测试'}])
    // 存储所有城市
    let allCities = ref({})

    // 发送请求获取城市信息
    onMounted( async ()=>{
        let res = await axios.get('http://122.112.161.135:8000/city')
        hotCities.value = res.data.data.hotCities
        allCities.value = res.data.data.cities
     

        $store.$patch({
            piniaCities: allCities.value
        })
    })
 

    return {
        hotCities,
        allCities,
   
    }
}